import { cancelRegistrationBatch } from '@/api/activity/activity'
import { isArray } from 'lodash-es';
export default {
    data() {
        return {
            isMessage: true,
        }
    },
    methods: {

        async batchCancel({ title, ids, callback, okText, cancelText }) {
            if (isArray(ids) && !ids.length) {
                return this.$message.warning('请选择取消报名的人员！');
            }
            // 驳回
            let remarks = ''
            this.isMessage = true
            this.$confirm({
                title,
                width: 600,
                okText,
                cancelText,
                icon: 'exclamation-circle',
                content: h => {
                    const descs = [];
                    if (isArray(ids)) {
                        descs.push(h('div', {
                            style: {
                                color: '#1D2129',
                                marginTop: '10px'
                            }
                        }, [
                            `确定要给已选的${ids.length}位参会者批量取消报名？取消成功后，如有相关报名费用将原路退回参会者付款账户`
                        ]), h('div', {
                            style: {
                                color: '#FF7D00',
                                marginTop: '10px',
                                marginBottom: '10px'
                            }
                        }, [
                            '注意：①、已签到的无法再取消报名；②、活动结束后，已进行资金结算的无法再取消报名；'
                        ]))
                    } else {
                        ids = [ids]
                    }

                    return h('div', [
                        ...descs,
                        h('div', {
                            style: {
                                display: 'flex',
                                paddingTop: '20px'
                            }
                        }, [
                            h('span', {
                                style: {
                                    color: 'red',
                                    marginRight: '3px'
                                }
                            }, '*'),
                            h('span', {
                                style: {
                                    whiteSpace: 'nowrap'
                                }
                            }, '取消原因：'),
                            h('a-textarea', {
                                style: {
                                    width: '100%',
                                    height: '100px',
                                    marginRight: '10px'
                                },
                                attrs: {
                                    placeholder: '请输入取消原因',
                                },
                                rows: 4,
                                on: {
                                    change: (e) => {
                                        remarks = e.target.value
                                    }
                                }

                            })
                        ]),
                        h(
                            'a-checkbox',
                            {
                                props: {
                                    checked: this.isMessage
                                },
                                on: {
                                    change: e => {
                                        this.isMessage = e.target.checked
                                    }
                                }
                            },
                            `同步发送取消报名短信通知`
                        )
                    ])
                },
                okText,
                cancelText,
                centered: true,
                onOk: () => {
                    return new Promise(async (resolve, reject) => {

                        try {
                            if (!remarks) {
                                reject()
                                return this.$message.warning('请输入取消原因！')
                            }
                            await cancelRegistrationBatch({ registerIds: ids, remarks, isMessage: this.isMessage })
                            callback && callback()
                            resolve()
                        } catch (error) {
                            reject(error)
                            return
                        }
                    })
                }
            })
        }
    },
};